package com.pc.web.member;


import java.io.IOException;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.TagSupport;

public class PageListTag extends TagSupport {
     /**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private int page;
    private int firstPage;
    private int lastPage;
    private int totPage;
    private String pageLinkUrl;
    private boolean method;
    private String status;
    private String searchWord;
    
    @Override
    public int doEndTag() throws JspException {
          StringBuilder pageTag = new StringBuilder();
          if (!method) {
                pageTag.append("<div class=\"paginate\">");
                if (firstPage != 1)
                      pageTag.append("<a href=\"" + pageLinkUrl + "&#63page="
                                 + (firstPage - 1) +  "&amp;searchWord=" + searchWord +
                                 "&amp;status=" + status +
                    		  "\" class=\"prev\">이전</a>");
                for (int i = firstPage; i < lastPage + 1; i++) {
                      // 현재 페이지는 <strong>으로 감싸서 표현
                      if (page == i)
                           pageTag.append("      <a href=\"" + pageLinkUrl + "&#63;page="
                                       + i + "&amp;status=" + status + "&amp;searchWord=" + searchWord +
                                       "\"><strong>" + i + "</strong></a>");
                      else
                           pageTag.append("      <a href=\"" + pageLinkUrl + "&#63;page="
                                       + i +  "&amp;status=" + status + "&amp;searchWord=" + searchWord +
                                       "\">" + i + "</a>");
                }
                if (lastPage < totPage)
                      pageTag.append("<a href=\"" + pageLinkUrl + "&#63page="
                                 + (lastPage + 1) +  "&amp;status=" + status + "&amp;searchWord=" + searchWord +
                                 "\" class=\"next\">다음</a>");
                pageTag.append("</div>");
          } else {
                pageTag.append("<div class=\"paginate\">");
                if (firstPage != 1)
                      pageTag.append("<a href=\"" + pageLinkUrl + "&#63page="
                                 + (firstPage - 1) +  "&amp;status=" + status + "&amp;searchWord=" + searchWord +
                                 "\" class=\"prev\">이전</a>");
                for (int i = firstPage; i < lastPage + 1; i++) {
                      // 현재 페이지는 <strong>으로 감싸서 표현
                      if (page == i)
                           pageTag.append("      <a href=\"" + pageLinkUrl + "&#63page="
                                       + i + "&amp;status=" + status + "&amp;searchWord=" + searchWord +
                                       "\"><strong>" + i + "</strong></a>");
                      else
                           pageTag.append("      <a href=\"" + pageLinkUrl + "&#63;page="
                                       + i +  "&amp;status=" + status + "&amp;searchWord=" + searchWord +
                                       "\">" + i + "</a>");
                }
                if (lastPage < totPage)
                      pageTag.append("<a href=\"" + pageLinkUrl + "&#63page="
                                 + (lastPage + 1) + "&amp;status=" + status + "&amp;searchWord=" + searchWord +
                                 "\" class=\"next\">다음</a>");
                pageTag.append("</div>");
          }
          try {
                pageContext.getOut().write(pageTag.toString());
          } catch (IOException e) {
                e.printStackTrace();
          }
          return EVAL_PAGE;
    }
    
    
    
    public void setSearchWord(String searchWord) {
		this.searchWord = searchWord;
	}
    public void setStatus(String status) {
		this.status = status;
	}
	public void setPage(int page) {
          this.page = page;
    }
    public void setFirstPage(int firstPage) {
          this.firstPage = firstPage;
    }
    public void setLastPage(int lastPage) {
          this.lastPage = lastPage;
    }
    public void setTotPage(int totPage) {
          this.totPage = totPage;
    }
    public void setPageLinkUrl(String pageLinkUrl) {
          this.pageLinkUrl = pageLinkUrl;
    }
    public void setMethod(boolean method) {
          this.method = method;
    }
}